<template>
  <div>
    <a-form-model :layout="form.layout" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
      <a-col>
        <a-form-model-item label="信息">
          <a-input v-model="form.message" placeholder="input placeholder"/>
        </a-form-model-item>
      </a-col>

      <a-form-model-item label="发送给">
        <a-input v-model="form.userId" placeholder="input placeholder"/>
      </a-form-model-item>
      <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
        <a-button type="primary" @click="onSubmit">
          提交
        </a-button>
      </a-form-model-item>
    </a-form-model>



  </div>
</template>
<script>
import WebIM from "@/utils/WebIM";

export default {
  name: "LiaoTian",
  data() {
    return {
      labelCol: {span: 4},
      wrapperCol: {span: 14},
      form: {
        layout: 'horizontal',
        message: 'nmy测试',
        userId: '123',
      },
    };
  },
  methods: {
    onSubmit() {
      this.sendPrivateText();
    },
    sendPrivateText() {
      let that = this;
      let id = WebIM.conn.getUniqueId();                 // 生成本地消息id
      let msg = new WebIM.message('txt', id);      // 创建文本消息
      msg.set({
        msg: that.form.message,                  // 消息内容
        to: that.form.userId,                          // 接收消息对象（用户id）
        chatType: 'singleChat',                  // 设置为单聊
        success: function (id, serverMsgId) {
          console.log('send private text Success'+id+serverMsgId);
        },                                       // 对成功的相关定义，sdk会将消息id登记到日志进行备份处理
        fail: function (e) {
          console.log("Send private text error" +e);
        }                                        // 对失败的相关定义，sdk会将消息id登记到日志进行备份处理
      });
      WebIM.conn.send(msg.body);
    },


  },


}
</script>

<style scoped>

</style>
